﻿/**
 * File:   gesture_lock.h
 * Author: AWTK Develop Team
 * Brief:  九宫格手势密码控件。
 *
 * Copyright (c) 2021 - 2021 Guangzhou ZHIYUAN Electronics Co.,Ltd.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * License file for more details.
 *
 */

/**
 * History:
 * ================================================================
 * 2021-02-20 Zhang Zhongji <zhangzhongji@zlg.cn> created
 *
 */


#ifndef TK_GESTURE_LOCK_H
#define TK_GESTURE_LOCK_H

#include "base/widget.h"

BEGIN_C_DECLS
typedef enum _gesture_lock_state_t {
  INIT,
  PRESSED,
  PASS,
  FAILED
} gesture_lock_state_t;

/**
 * @class gesture_lock_t
 * @parent widget_t
 * @annotation ["scriptable","design","widget"]
 * 九宫格手势密码控件。
 * 在xml中使用"gesture\_lock"标签创建控件。如：
 *
 * ```xml
 * <!-- ui -->
 * <gesture_lock x="c" y="50" w="100" h="100" show_gesture="false"/>
 * ```
 *
 * 可用通过style来设置控件的显示风格，如字体的大小和颜色等等。如：
 * 
 * ```xml
 * <!-- style -->
 * <gesture_lock>
 *   <style name="default">
 *     <normal fg_color="#219aff" selected_fg_color="#5249e7" />
 *   </style>
 * </gesture_lock>
 * ```
 */
typedef struct _gesture_lock_t {
  widget_t widget;
  /**
   * @property {bool_t} show_gesture
   * @annotation ["readable", "writable"]
   * 是否显示手势轨迹
   */
  bool_t show_gesture;

  /**
   * @property {str_t} password
   * @annotation ["readable"]
   * 输入的手势密码
   */
  str_t password;
/* private */
  bool_t pressed;
  point_t base_points[9];
  darray_t *input_points;
  point_t current_position;
  float_t r;
  uint32_t timer_id;
} gesture_lock_t;

/**
 * @method gesture_lock_create
 * @annotation ["constructor", "scriptable"]
 * 创建gesture_lock对象
 * @param {widget_t*} parent 父控件
 * @param {xy_t} x x坐标
 * @param {xy_t} y y坐标
 * @param {wh_t} w 宽度
 * @param {wh_t} h 高度
 *
 * @return {widget_t*} gesture_lock对象。
 */
widget_t* gesture_lock_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);

/**
 * @method gesture_lock_cast
 * 转换为gesture_lock对象(供脚本语言使用)。
 * @annotation ["cast", "scriptable"]
 * @param {widget_t*} widget gesture_lock对象。
 *
 * @return {widget_t*} gesture_lock对象。
 */
widget_t* gesture_lock_cast(widget_t* widget);


#define GESTURE_LOCK_PROP_PASSWORD "password"
#define GESTURE_LOCK_PROP_SHOW_GESTURE "show_gesture"
#define GESTURE_LOCK_PROP_P0_X     "P0_X"
#define GESTURE_LOCK_PROP_P0_Y     "P0_Y"
#define GESTURE_LOCK_PROP_P1_X     "P1_X"
#define GESTURE_LOCK_PROP_P1_Y     "P1_Y"
#define GESTURE_LOCK_PROP_P2_X     "P2_X"
#define GESTURE_LOCK_PROP_P2_Y     "P2_Y"
#define GESTURE_LOCK_PROP_P3_X     "P3_X"
#define GESTURE_LOCK_PROP_P3_Y     "P3_Y"
#define GESTURE_LOCK_PROP_P4_X     "P4_X"
#define GESTURE_LOCK_PROP_P4_Y     "P4_Y"
#define GESTURE_LOCK_PROP_P5_X     "P5_X"
#define GESTURE_LOCK_PROP_P5_Y     "P5_Y"
#define GESTURE_LOCK_PROP_P6_X     "P6_X"
#define GESTURE_LOCK_PROP_P6_Y     "P6_Y"
#define GESTURE_LOCK_PROP_P7_X     "P7_X"
#define GESTURE_LOCK_PROP_P7_Y     "P7_Y"
#define GESTURE_LOCK_PROP_P8_X     "P8_X"
#define GESTURE_LOCK_PROP_P8_Y     "P8_Y"

#define WIDGET_TYPE_GESTURE_LOCK "gesture_lock"

#define GESTURE_LOCK(widget) ((gesture_lock_t*)(gesture_lock_cast(WIDGET(widget))))

/*public for subclass and runtime type check*/
TK_EXTERN_VTABLE(gesture_lock);

END_C_DECLS

#endif /*TK_GESTURE_LOCK_H*/
